package com.damin.liuxiaojing;

public class SelectSort {

    public static void sort(int[] r) {
        int n = r.length;
        for (int i = 0; i < n - 1; i++) {// n-1趟
            int min = i;
            for (int j = i + 1; j < n; j++) {
                if (r[j] < r[min]) {
                    min = j;
                }
            }
            if (min != i) {
                int temp = r[min];
                r[min] = r[i];
                r[i] = temp;
            }
        }
    }

    public static void display(int[] r) {
        for (int item : r) {
            System.out.print(item + " ");
        }
        System.out.println();
    }

    public static void main(String[] args) {
        int[] r = new int[] {3, 5, 5, 4, 120, 43, 1, 76, 78, 12, 346};
        SelectSort.sort(r);
        SelectSort.display(r);
    }

}
